package org.dftproject.genesis.ui.pages.pedigree.zoom;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;

public class ZoomControlFigure extends Figure {
	
	public static final int inset = 3;
	public static final int width = 31;
	public static final Color backgroundColor = new Color(null, 238, 238, 255);
	public static final Color borderColor = new Color(null, 128, 128, 128);
	
	public ZoomControlFigure(ZoomManager zoomManager) {
		ToolbarLayout layout = new ToolbarLayout(); 
		layout.setSpacing(inset);
		this.setLayoutManager(layout);

		this.setBorder(new MarginBorder(inset + 1, inset + 1, inset + 1, inset + 1));
		
		ZoomButtonFigure zoomIn = new ZoomButtonFigure(ZoomButtonFigure.IN, zoomManager);
		zoomIn.setSize(width, width);
		this.add(zoomIn);
		
		ZoomBarFigure bar = new ZoomBarFigure(zoomManager);
		this.add(bar);
		
		ZoomButtonFigure zoomOut = new ZoomButtonFigure(ZoomButtonFigure.OUT, zoomManager);
		zoomOut.setSize(width, width);
		this.add(zoomOut);
	}
	
	@Override
	public void paint(Graphics graphics) {		
		graphics.setAntialias(SWT.ON);
		
		Rectangle bounds = getBounds();

		graphics.setBackgroundColor(backgroundColor);
		graphics.fillRoundRectangle(new Rectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1), inset * 2, inset * 2);
		
		graphics.setForegroundColor(borderColor);
		graphics.drawRoundRectangle(new Rectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1), inset * 2, inset * 2);

		super.paint(graphics);
	}

}
